package com.ibm.risk.irmp.base.config.rest;


import com.ibm.risk.irmp.base.auth.service.IUserManagementService;
import com.ibm.risk.irmp.base.config.service.IConfigService;
import com.ibm.risk.irmp.common.auth.AuthUtils;
import com.ibm.risk.irmp.common.auth.vo.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/v2/config")
public class ConfigController implements IConfigService {

    @Autowired
    private IUserManagementService userService;

    @Autowired
    private IConfigService configService;

    @GetMapping(value = "/current")
    public Map<String, Object> current() {
        Map<String, Object> result = new HashMap<>();
        LoginUser user = AuthUtils.getLoginUser();

        result.put("orgCode", user.getBizOrgs().get(0).getBranchCode());
        result.put("orgName", user.getBizOrgs().get(0).getBranchName());
        result.put("mngOrgCode", user.getMngOrgs().get(0).getBranchCode());
        result.put("mngOrgName", user.getMngOrgs().get(0).getBranchName());
        return (result);
    }

//    @Override
//    @GetMapping(value = "/hq-fin-branch-code")
//    public String getHqFinBranchCode() {
//        return configService.getHqFinBranchCode();
//    }

    @Override
    @GetMapping(value = "/latest-data-date")
    public String getLatestDataDate() {
        return configService.getLatestDataDate();
    }

//    @Override
//    @GetMapping(value = "/hq-mng-branch-code")
//    public String getHqMngBranchCode() {
//        return configService.getHqMngBranchCode();
//    }
}
